import java.util.Scanner;

public class NGuessNumber {
    public static void main(String[] args) {
        NGuessNumber nGuessNumber = new NGuessNumber();
        int a[] = nGuessNumber.generateAnswer();

        while(true){
            int x = nGuessNumber.isWin(a);
            if(x==4){
                break;
            }else{
                System.out.println("您对了"+x+"个数");
            }

        }
    }

    public int[] generateAnswer(){

        int a[] =new int[4];
        for(int i=0;i<4;i++){
            int x=(int)(Math.random()*10);
            int m=0;
            for(int j=i-1;j>0;j--){
                if(a[j]==x){
                    m=1;
                }
            }
            if(m!=1){
                a[i]=x;
            }else{
                i--;
            }

        }
        return a;
    }
    public int[] getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        int a[] = new int[4];
        for(int i=0;i<4;i++){
            System.out.println("请输入第"+(i+1)+"个数字");
            a[i] = scanner.nextInt();
        }
        return a;
    }


    public int compareGuessAnswer(int a[],int b[]){
        int x=0;
        for(int i=0;i<a.length;i++){
            for(int j=0;j<b.length;j++){
                if(a[i]==b[j]){
                    x++;
                }
            }
        }
        return x;
    }
    public int isWin(int a[]){
        int m[] = getPlayerInput();
        int n = compareGuessAnswer(a,m);
        if(n==4){
            System.out.println("您赢了");
        }else{
            System.out.println("您没赢");
        }
        return n;
    }

}
